package edu.neusoft.yuejian_09.activity;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;


import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.adapter.MyPostListAdapter;
import edu.neusoft.yuejian_09.bean.Show;
import edu.neusoft.yuejian_09.model.UserModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/10/13.
 */

public class MyPostListActivity extends Activity {
    //声明
    private ImageView left;
    private int u_id;
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_post);
        initViews();//初始化
        initData();//点击事件处理
        initEvent();
    }

    private void initViews() {
        recyclerView = (RecyclerView) findViewById(R.id.my_post);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局

        left = (ImageView) findViewById(R.id.left);
    }
    private void initEvent() {
        //返回上一页
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


    }

    private void initData() {
        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id = sp.getInt("user_id", 0);
        Log.d("we","u_id");


        UserModel userModel = new UserModel();
                //发送请求
                Call<List<Show>> call = userModel.getMypostlist
                        (u_id);
                //2.处理结果
                call.enqueue(new Callback<List<Show>>() {
                    @Override
                    public void onResponse(Call<List<Show>> call, Response<List<Show>> response) {
                        List<Show> data = (List<Show>) response.body();  //获取数据
                        recyclerView.setAdapter(new MyPostListAdapter(MyPostListActivity.this, data));
                    }

                    @Override
                    public void onFailure(Call<List<Show>> call, Throwable t) {

                    }

                });
}
}

